<template>
  <div class="container">
      <h3>{{timer}}</h3>
  </div>
</template>

<script>
export default {
  data() {
    return {
        timer:"",
    }
  },
  methods:{
      djs(){
        var now = new Date().getTime(); //获取现在时间戳
        var xin = new Date('2022-05-01 00:00:00').getTime();
        var cha = xin - now; 
        var day = Math.floor(cha/24/60/60/1000);
        var hours =Math.floor(cha/60/60/1000%24);
        var fen = Math.floor(cha/60/1000%60);
        var miao = Math.floor(cha/1000%60);
        console.log(day,hours,fen,miao)
        this.timer = `距离5.1劳动节倒计时还有${day}天${hours}小时${fen}分${miao}秒`
      }
   },
   //页面加载事件 created() /mounted()
    mounted(){
        setInterval(()=>{
            this.djs() 
        },1000)
        
    }

}
</script>

<style scoped>

</style>
